package nc.impl.byb.service;

import java.util.List;

import nc.bs.framework.common.InvocationInfoProxy;
import nc.bs.logging.Logger;
import nc.bs.pfxx.ResponseMessage;
import nc.itf.byb.service.ISendDocService;
import nc.vo.pfxx.xxconfig.RequestParameter;
import nc.vo.pub.BusinessException;

import org.dom4j.Document;

import com.yonyou.byb.BybConstant;
import com.yonyou.byb.ConfigContext;
import com.yonyou.byb.utils.DocumentChange;

public class SendDocServiceImpl implements ISendDocService {

	@Override
	public List<ResponseMessage> sendDoc(Document doc) throws BusinessException {
		Logger.init("byb");
		try {
			InvocationInfoProxy.getInstance().setUserDataSource(ConfigContext.getInstance().getDatasource());
			InvocationInfoProxy.getInstance().setUserCode(BybConstant.BYB_USER_CODE);
			InvocationInfoProxy.getInstance().setUserId(BybConstant.BYB_USER_ID);
			InvocationInfoProxy.getInstance().setGroupId(BybConstant.GROUP_ID);
			
			nc.bs.pfxx.XChangeContext context = new nc.bs.pfxx.XChangeContext();
			nc.vo.pfxx.util.PfxxUtils.registerContext(context);
			RequestParameter reqparam = new RequestParameter();
			reqparam.setAccount("");
			
			context.init(reqparam, DocumentChange.parse(doc));
			nc.bs.pfxx.process.XChangeProcessor process = new nc.bs.pfxx.process.XChangeProcessor();
			return process.newProcessMessage_AllOrNone(DocumentChange.parse(doc));
		} catch (Exception e) {
			
			Logger.error(e.getMessage(), e);
			throw new BusinessException(e.getMessage(),e);
		}
		
	}

}
